/*
 * Vektor.cpp
 *
 *  Created on: Feb 14, 2011
 *      Author: alki
 */

#include "Vektor.h"
#include "Matrix.h"

#include <iostream>
#include <stdlib.h>

using namespace std;

Vektor::Vektor() {
	this->m_x=0;
	this->m_y=0;
	this->m_z=0;
}

Vektor::Vektor(float x,float y,float z) {
	this->m_x=x;
	this->m_y=y;
	this->m_z=z;
}

Vektor::~Vektor() {
}

void Vektor::setAngle(double alpha,double beta) {
	this->m_x=sin(alpha);
	this->m_y=sin(beta);
	this->m_z=-1;
	this->Normalize();
}

float Vektor::ScalarProduct(const Vektor &v) const {
	return (this->m_x*v.m_x + this->m_y*v.m_y + this->m_z*v.m_z);
}

Vektor Vektor::CrossProduct(const Vektor &v) const {
	Vektor neu(
			this->m_y*v.m_z - this->m_z*v.m_y,
			this->m_z*v.m_x - this->m_x*v.m_z,
			this->m_x*v.m_y - this->m_y*v.m_x);
	return neu;
}

Vektor Vektor::operator-(const Vektor &v) const {
	Vektor neu(
			this->m_x-v.m_x,
			this->m_y-v.m_y,
			this->m_z-v.m_z);
	return neu;
}

Vektor Vektor::operator+(const Vektor &v) const {
	Vektor neu(
			this->m_x+v.m_x,
			this->m_y+v.m_y,
			this->m_z+v.m_z);
	return neu;
}

Vektor Vektor::operator*(float n) const {
	Vektor neu(
			this->m_x*n,
			this->m_y*n,
			this->m_z*n);
	return neu;
}

void Vektor::Rotate(float x,float y,float z,bool rueck) {
	Matrix rotX;
	Matrix rotY;
	Matrix rotZ;

	rotX.a_11=1;
	rotX.a_22=rotX.a_33=cos(x);
	rotX.a_32=sin(x);
	rotX.a_23=-sin(x);

	rotY.a_22=1;
	rotY.a_11=rotY.a_33=cos(y);
	rotY.a_13=sin(y);
	rotY.a_31=-sin(y);

	rotZ.a_33=1;
	rotZ.a_11=rotZ.a_22=cos(z);
	rotZ.a_21=sin(z);
	rotZ.a_12=-sin(z);

	Matrix rot;
	if(!rueck)
		rot=(rotX*rotY)*rotZ;
	else
		rot=(rotZ*rotY)*rotX;

	Vektor neu=rot*(*this);

	this->m_x=neu.m_x;
	this->m_y=neu.m_y;
	this->m_z=neu.m_z;
}

void Vektor::out() const {
	cout << this->m_x << " | " << this->m_y << " | " << this->m_z << endl;
}
